/*
 * glConsole.h
 *
 *  Created on: Oct 16, 2012
 *      Author: travis
 *
 *      Creating console over screen
 *      In ctor need to setup: screen size, path to log file and command file and
 *      path to console/
 *      All textures from console directory are loaded so it can use different
 *      background texture.
 *
 *      commands are loaded from command file. It has own ID witch is
 *      returned when command was called.
 */

#pragma once

#ifdef _WIN32 
#include <windows.h> 
#include "SDL.h"
#include "SDL_thread.h"
#else
#include "SDL/SDL.h"
#include "SDL/SDL_thread.h"
#endif

#include "glFont.h"        // trida fontu
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>

#include <fstream>

#include "GL/gl.h"
#include "../TexPool.h"
#include "../engine/engineSettings.h"

// interni prikazy

#define     C_NEW_LINE  -1
#define     C_CLEAR     0
#define     C_HELP      1
#define     C_EXIT      2
#define     C_LOG       3

using namespace std;

class glConsole
{
public:
	int num_lines; // pocet zaznamu
	char *log_file; // ukazatel na adresu log souboru
	vector<string> lines; // zaznamy console vector
	vector<string> commands; // importovane prikazy ze souboru
	string command_line; // aktualne editovany radek (hlidany ve funkci get_line, vraci true pokud bylo stisknuto enter)

	void log(); // loguje celou konzoli do souboru na adrese log_file
	void load_com(const char *file_name); // nacte uzivatelske prikazy ze souboru
	void clear_lines();
	void show_cursor();
	void show(); // zobrazi konzoli
	void show_lines(); // vykresli text
	int command(string com); // prikaz vykresli na surface console
	void print(const char *fmt, ...); // vypisuje do console
	int get_line(SDL_Event key_pressed); // vraci vstupni prikazy (pokuze)

	glConsole();
	// konstruktor, velikost plochy, soubor s texturou fontu, adresa log souboru a adresa souboru s prikazy
	~glConsole();
protected:
	GLuint background;
	int cur; // blikani kurzoru
	int cur_pos; // pozice textoveho kurzoru
	int max_cur_pos; // delka napsaneho textu
	stringstream s_stream;
	string s;

	TexPool *textures;
	glFont *font;

	int c_pos; // pozice viditelne casti pri rolovani

	SDL_sem *Lock;
};
